import { BillApi } from '@/api/Bill.api.js'
import { Common } from '@/utils/common.js'
import config from '@/config'
const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro.replace('/api', '/')

export default {
  name: '',

  data () {
    return {
      isShowTableShangbaomingxiModal: false,
      companyName: null,
      companyId: null,
      year: null,
      month: null,
      startDate: null,
      endDate: null,
      tableData: [],
      tableComone: {
        pageIndex: 1, // 页码
        totalRows: 0, // 总条数
        pageSize: 10 // 当前页面展示条数
      },
      formItem: [
        { text: '总计', key: 'totalAmt', value: '' }
      ]
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    /**
     * 分页页码变动
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.tableComone.pageIndex = val
      this.query()
    },
    /**
     * 分页页码变动
     * @param {Number} val pageSize
     */
    onpageSizeChange (val) {
      this.tableComone.pageIndex = 1
      this.tableComone.pageSize = val
      this.query()
    },
    // 日期选择
    handleChangeDatePicker (model, val) {
      console.log('model: ', model)
      console.log('val: ', val)
      this[model] = val
      console.log(this[model])
    },
    /**
     * 分页查询接口
     * @param {Object} obj {pageIndex, pageSize}
     */
    async query () {
      var params = {
        CompanyId: this.companyId,
        Year: this.year,
        Month: this.month,
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize
      }
      let res = await BillApi.cIDetails(params)
      console.log('商保明细列表res: ', res)
      if (res.status === 200 && res.data.success) {
        this.tableData = res.data.data.items
        this.tableComone.totalRows = res.data.totalRows
        this.companyName = res.data.data.companyName

        this.formItem.map(col => {
          col.value = res.data.data[col.key]
        })
      } else {
        this.tableData = []
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
      this.loading = false
    },

    ok () {
    },

    cancel () {
    },

    handleExportData () {
    },

    parsingItems (row, item, oneTitle, twoTitle1, twoTitle2, type) {
      var sumTitle = oneTitle + twoTitle1 + type
      console.log('sumTitle: ', sumTitle)
      row[sumTitle] = item[twoTitle1][type]
    },

    // 导出
    async exportCIDetails () {
      var params = {
        companyID: this.companyId,
        companyName: this.companyName,
        year: this.year,
        month: this.month,
        StartDate: this.startDate+'-1',
        EndDate: this.endDate+'-1'
        // pageIndex: this.tableComone.pageIndex,
        // pageSize: this.tableComone.pageSize,
      }
      console.log('导出params: ', params)
      let res = await BillApi.exportCIDetails(params)
      if (res.status === 200 && res.data.success) {
        console.log('❤ 返回链接: ', baseUrl + res.data.message)
        window.open(baseUrl + res.data.message, '_blank')
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    }
  }
}
